home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 21
/
Cream of the Crop 21 (Terry Blount) (October 1996).iso
/
os2
/
e33el2.zip
/
emacs
/
19.33
/
lisp
/
holidays.el
< prev
next >
Wrap
Lisp/Scheme
|
1996-03-22
|
16KB
|
385 lines
;;; holidays.el --- holiday functions for the calendar package
;; Copyright (C) 1989, 1990, 1992, 1993, 1994 Free Software Foundation, Inc.
;; Author: Edward M. Reingold <reingold@cs.uiuc.edu>
;; Keywords: holidays, calendar
;; This file is part of GNU Emacs.
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;; This collection of functions implements the holiday features as described
;; in calendar.el.
;; Comments, corrections, and improvements should be sent to
;; Edward M. Reingold Department of Computer Science
;; (217) 333-6733 University of Illinois at Urbana-Champaign
;; reingold@cs.uiuc.edu 1304 West Springfield Avenue
;; Urbana, Illinois 61801
;; Technical details of all the calendrical calculations can be found in
;; ``Calendrical Calculations'' by Nachum Dershowitz and Edward M. Reingold,
;; Software--Practice and Experience, Volume 20, Number 9 (September, 1990),
;; pages 899-928. ``Calendrical Calculations, Part II: Three Historical
;; Calendars'' by E. M. Reingold, N. Dershowitz, and S. M. Clamen,
;; Software--Practice and Experience, Volume 23, Number 4 (April, 1993),
;; pages 383-404.
;; Hard copies of these two papers can be obtained by sending email to
;; reingold@cs.uiuc.edu with the SUBJECT "send-paper-cal" (no quotes) and
;; the message BODY containing your mailing address (snail).
;;; Code:
(require 'calendar)
(autoload 'holiday-julian "cal-julian"
"Holiday on MONTH, DAY (Julian) called STRING."
t)
(autoload 'holiday-hebrew "cal-hebrew"
"Holiday on MONTH, DAY (Hebrew) called STRING."
t)
(autoload 'holiday-rosh-hashanah-etc "cal-hebrew"
"List of dates related to Rosh Hashanah, as visible in calendar window."
t)
(autoload 'holiday-hanukkah "cal-hebrew"
"List of dates related to Hanukkah, as visible in calendar window."
t)
(autoload 'holiday-passover-etc "cal-hebrew"
"List of dates related to Passover, as visible in calendar window."
t)
(autoload 'holiday-tisha-b-av-etc "cal-hebrew"
"List of dates around Tisha B'Av, as visible in calendar window."
t)
(autoload 'holiday-islamic "cal-islam"
"Holiday on MONTH, DAY (Islamic) called STRING."
t)
(autoload 'holiday-chinese-new-year "cal-china"
"Date of Chinese New Year."
t)
(autoload 'solar-equinoxes-solstices "solar"
"Date and time of equinoxes and solstices, if visible in the calendar window.
Requires floating point."
t)
(defun holidays (&optional arg)
"Display the holidays for last month, this month, and next month.
If called with an optional prefix argument, prompts for month and year.
This function is suitable for execution in a .emacs file."
(interactive "P")
(save-excursion
(let* ((completion-ignore-case t)
(date (if arg
(calendar-read-date t)
(calendar-current-date)))
(displayed-month (extract-calendar-month date))
(displayed-year (extract-calendar-year date)))
(list-calendar-holidays))))
(defun check-calendar-holidays (date)
"Check the list of holidays for any that occur on DATE.
The value returned is a list of strings of relevant holiday descriptions.
The holidays are those in the list calendar-holidays."
(let* ((displayed-month (extract-calendar-month date))
(displayed-year (extract-calendar-year date))
(h (calendar-holiday-list))
(holiday-list))
(while h
(if (calendar-date-equal date (car (car h)))
(setq holiday-list (append holiday-list (cdr (car h)))))
(setq h (cdr h)))
holiday-list))
(defun calendar-cursor-holidays ()
"Find holidays for the date specified by the cursor in the calendar window."
(interactive)
(message "Checking holidays...")
(let* ((date (calendar-cursor-to-date t))
(date-string (calendar-date-string date))
(holiday-list (check-calendar-holidays date))
(holiday-string (mapconcat 'identity holiday-list "; "))
(msg (format "%s: %s" date-string holiday-string)))
(if (not holiday-list)
(message "No holidays known for %s" date-string)
(if (<= (length msg) (frame-width))
(message "%s" msg)
(set-buffer (get-buffer-create holiday-buffer))
(setq buffer-read-only nil)
(calendar-set-mode-line date-string)
(erase-buffer)
(insert (mapconcat 'identity holiday-list "\n"))
(goto-char (point-min))
(set-buffer-modified-p nil)
(setq buffer-read-only t)
(display-buffer holiday-buffer)
(message "Checking holidays...done")))))
(defun mark-calendar-holidays ()
"Mark notable days in the calendar window."
(interactive)
(setq mark-holidays-in-calendar t)
(message "Marking holidays...")
(let ((holiday-list (calendar-holiday-list)))
(while holiday-list
(mark-visible-calendar-date
(car (car holiday-list)) calendar-holiday-marker)
(setq holiday-list (cdr holiday-list))))
(message "Marking holidays...done"))
(defun list-calendar-holidays ()
"Create a buffer containing the holidays for the current calendar window.
The holidays are those in the list calendar-notable-days. Returns t if any
holidays are found, nil if not."
(interactive)
(message "Looking up holidays...")
(let ((holiday-list (calendar-holiday-list))
(m1 displayed-month)
(y1 displayed-year)
(m2 displayed-month)
(y2 displayed-year))
(if (not holiday-list)
(progn
(message "Looking up holidays...none found")
nil)
(set-buffer (get-buffer-create holiday-buffer))
(setq buffer-read-only nil)
(increment-calendar-month m1 y1 -1)
(increment-calendar-month m2 y2 1)
(calendar-set-mode-line
(if (= y1 y2)
(format "Notable Dates from %s to %s, %d%%-"
(calendar-month-name m1) (calendar-month-name m2) y2)
(format "Notable Dates from %s, %d to %s, %d%%-"
(calendar-month-name m1) y1 (calendar-month-name m2) y2)))
(erase-buffer)
(insert
(mapconcat
'(lambda (x) (concat (calendar-date-string (car x))
": " (car (cdr x))))
holiday-list "\n"))
(goto-char (point-min))
(set-buffer-modified-p nil)
(setq buffer-read-only t)
(display-buffer holiday-buffer)
(message "Looking up holidays...done")
t)))
(defun calendar-holiday-list ()
"Form the list of holidays that occur on dates in the calendar window.
The holidays are those in the list calendar-holidays."
(let ((p calendar-holidays)
(holiday-list))
(while p
(let* ((holidays
(if calendar-debug-sexp
(let ((stack-trace-on-error t))
(eval (car p)))
(condition-case nil
(eval (car p))
(error (beep)
(message "Bad holiday list item: %s" (car p))
(sleep-for 2))))))
(if holidays
(setq holiday-list (append holidays holiday-list))))
(setq p (cdr p)))
(setq holiday-list (sort holiday-list 'calendar-date-compare))))
;; Below are the functions that calculate the dates of holidays; these
;; are ev